package com.zaaach.citypicker;



import com.google.gson.Gson;
import com.zaaach.citypicker.adapter.OnPickListener;
import com.zaaach.citypicker.model.City;
import com.zaaach.citypicker.model.HotCity;
import com.zaaach.citypicker.model.LocateState;
import com.zaaach.citypicker.model.LocatedCity;
import ohos.aafwk.ability.fraction.Fraction;
import ohos.aafwk.ability.fraction.FractionAbility;
import ohos.aafwk.ability.fraction.FractionManager;
import ohos.aafwk.ability.fraction.FractionScheduler;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.app.Context;

import java.lang.ref.WeakReference;
import java.util.List;
import java.util.NoSuchElementException;

/**
 * @Author: Bro0cL
 * @Date: 2018/2/6 17:52
 */
public class CityPicker {
    private static final String TAG = "CityPicker";
    private static CityPicker instance;
    private boolean enableAnim;
    private int mAnimStyle;
    private LocatedCity mLocation;
    private List<HotCity> mHotCities;
    private OnPickListener mOnPickListener;

    private CityPicker(){}


    public synchronized static CityPicker getInstance() {
        if(instance == null)
            instance = new CityPicker();
        return instance;
    }

    /**
     * 启用动画效果，默认为false
     *
     * @param enable
     * @return CityPicker
     */
    public CityPicker enableAnimation(boolean enable){
        this.enableAnim = enable;
        return this;
    }
    /**
     * 设置选择结果的监听器
     *
     * @param listener
     * @return CityPicker
     */
    public CityPicker setOnPickListener(OnPickListener listener){
        this.mOnPickListener = listener;
        return this;
    }
    /**
     * 设置当前已经定位的城市
     *
     * @param location
     * @return CityPicker
     */
    public CityPicker setLocatedCity(LocatedCity location) {
        this.mLocation = location;
        return this;
    }

    public CityPicker setHotCities(List<HotCity> data){
        this.mHotCities = data;
        return this;
    }


    CityPickerDialog cityPickerDialog;
    public void show(Context context){
        cityPickerDialog = new CityPickerDialog(context);
        cityPickerDialog.setLocatedCity(mLocation);
        cityPickerDialog.setHotCities(mHotCities);
        cityPickerDialog.enableAnimation(enableAnim);
        cityPickerDialog.setOnPickListener(mOnPickListener);
        cityPickerDialog.show();

    }
    /**
     * 定位完成
     *
     * @param location
     * @param state
     */
    public void locateComplete(LocatedCity location, @LocateState.State int state){
        try {
            cityPickerDialog.locationChanged(location, state);
        }catch (NoSuchElementException e){}
    }

    public boolean isEnableAnim() {
        return enableAnim;
    }

    public LocatedCity getmLocation() {
        return mLocation;
    }

    public List<HotCity> getmHotCities() {
        return mHotCities;
    }
}
